class Brand < ApplicationRecord
  mount_uploader :avatar, BaseUploader
  mount_uploader :big_avatar, BaseUploader
  
  belongs_to :shop_category, optional: true

  has_many :shop_category_brands, dependent: :destroy
  has_many :shop_categories, through: :shop_category_brands
  has_many :favorites, as: :favoriteable
  has_many :spus
  
  def is_favorited?(user_id)
    favorite = Favorite.where(favoriteable_type: 'Brand', favoriteable_id: self.id, user_id: user_id).first
    !favorite.blank?
  end
end
